package org.amphiprion.descentv2assistant.adapter;

import java.text.MessageFormat;
import java.util.List;

import org.amphiprion.descentv2assistant.R;
import org.amphiprion.descentv2assistant.entity.Monster;
import org.amphiprion.descentv2assistant.util.SectionMap;

import android.content.Context;
import android.widget.SectionIndexer;

public class MonsterIndexer implements SectionIndexer {
	private final SectionMap<String, Monster> mSectionMap = new SectionMap<String, Monster>();
	private final Context mContext;

	public MonsterIndexer(Context paramContext, List<Monster> paramArrayList) {
		this.mContext = paramContext;
		for (int i = 0; i < paramArrayList.size(); i++) {
			Monster monster = paramArrayList.get(i);

			String sectionTitle = getSectionName(monster);

			this.mSectionMap.add(sectionTitle, monster);
		}
	}

	public int getEpisodesForSeason(int paramInt) {
		return this.mSectionMap.getCountForGroup(paramInt);
	}

	@Override
	public int getPositionForSection(int paramInt) {
		return this.mSectionMap.getFirstIndexInSection(paramInt);
	}

	@Override
	public int getSectionForPosition(int paramInt) {
		return this.mSectionMap.getSectionFromIndex(paramInt);
	}

	@Override
	public Object[] getSections() {
		return this.mSectionMap.getSections();
	}

	public String getSectionName(Monster m) {
		String s = null;
		if (m.isMajor()) {
			s = mContext.getResources().getString(R.string.act_major_header);
		} else {
			s = mContext.getResources().getString(R.string.act_minor_header);
		}
		s = MessageFormat.format(s, "" + m.getAct());
		return s;

	}
}